<?php
declare(strict_types=1);
namespace app\common\business;

use app\BaseController;
use app\common\lib\ClassArr;
use app\common\lib\Num;

class Sms extends BaseController{
    public static function sendCode(string $phoneNumber,int $len, $type='Ali'){
        #生成短信验证码 4位或者6位
        $code = Num::getCode($len);

        //工厂模式
//        $type = ucfirst($type);
//        $class = "app\common\lib\sms\\".$type."Sms";
//        $sms = $class::sendCode($phoneNumber,$code);

        $classStats = ClassArr::smsClassStat();
        $classObj = ClassArr::initClass($type, $classStats);
        $sms = $classObj::sendCode($phoneNumber,$code);

        if($sms){
            cache(config("redis.code_pre").$phoneNumber,$code,config("redis"));
        }

        return $sms;

    }
}